package com.eight.travel.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eight.travel.dao.StorePicMapper;
import com.eight.travel.pojo.StorePic;
import com.eight.travel.service.StorePicService;
import com.eight.travel.utils.BaseResp;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StorePicServiceImpl extends ServiceImpl<StorePicMapper, StorePic> implements StorePicService{

    @Resource
    StorePicMapper storePicMapper;

    @Override
    public BaseResp addPic(StorePic storePic) {
        int res = storePicMapper.insert(storePic);
        if(res == 1){
            return new BaseResp().SUCCESS2("添加图片成功");
        }
        return new BaseResp().FAIL("添加图片失败");
    }

    @Override
    public BaseResp deletePic(Integer spid) {
        int res = storePicMapper.deleteById(spid);
        if(res == 1){
            return new BaseResp().SUCCESS2("成功删除图片");
        }
        return new BaseResp().FAIL("删除图片失败");
    }

    @Override
    public BaseResp selectBySid(Integer sid) {
        List<StorePic> storePics = storePicMapper.selectBySid(sid);
        int i = storePicMapper.selectBySidRow(sid);
        if(storePics != null){
            return new BaseResp().SUCCESS("查看图片成功", storePics, i);
        }
        return new BaseResp().FAIL("查看图片失败");
    }
}
